<template>
	<view class="mainpadding_top">
		<view class="flexbetween">
			<textarea placeholder="请输入您对视频的描述吧" class="hei_text ershiba" style="width: 100%;height: 300rpx;"
				v-model="des"></textarea>
			<!-- <image src="https://mall.modounb.com//uploads/20240110/cda6f69f2a8d6f7c3d4a752fe97daa3e.jpg" mode="" class="radius" style="min-width: 230rpx;max-width: 230rpx;height: 300rpx;border-radius: 10rpx;"></image> -->
			<image :src="path_text+'?x-oss-process=video/snapshot,t_10000,m_fast'" class="radius"
				style="min-width: 230rpx;max-width: 230rpx;height: 300rpx;border-radius: 10rpx;" mode=""></image>
		</view>
		<view class="margin_top6">
			<view class="flexbetween">
				<view class="flexleft">
					<u-icon name="map" color="#333" size="20"></u-icon>
					<view class="hei_text ershiba">你在哪里？</view>
				</view>
				<view class="xiaolan ershil" @tap="changeaddress">{{citytext}}</view>
			</view>
			<!-- <view class="flexbetween margin_top5">
				<view class="flexleft">
					<u-icon name="attach" color="#333" size="20"></u-icon>
					<view class="hei_text ershiba">添加链接</view>
				</view>
				<u-icon name="arrow-right" color="#333" size="20"></u-icon>
			</view> -->
		</view>
		<view class="gudingdb ffffff mainpadding">
			<view class="bigbtn" @click="submit">发布</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				path_text: "",
				path: "",
				video_yy_id: "",
				longitude: "",
				latitude: "",
				des: "",
				citytext: "",
				getlocationflag:false,
				isload:false
			}
		},
		onLoad(options) {
			let data = JSON.parse(decodeURIComponent(options.msg))
			console.log("发布视频界面接受参数", data);
			this.path = data.path
			this.path_text = data.path_text
			this.video_yy_id = data.video_yy_id
			this.getlocation()
		},
		onShow() {
			if(this.getlocationflag){
				uni.$on("selectaddress", data => {
					this.citytext = data.citytext
					this.latitude = data.latitude
					this.longitude = data.longitude
				})
			}
			if(!this.getlocationflag && this.isload){
				this.getlocation()
			}
			
		},
		onUnload() {
			uni.$off("selectaddress")
		},
		methods: {
			changeaddress() {
				uni.navigateTo({
					url: "/pages_homepage/xuanzecs?type=1"
				})
			},
			getlocation() {
				let _this = this
				uni.getLocation({
					type: 'wgs84',
					success: function(res) {
						_this.isload = true
						console.log(res, "获取定位成功");
						_this.getlocationflag = true
						_this.latitude = res.latitude
						_this.longitude = res.longitude
						_this.getcityInfo()
					},
					fail(err) {
						_this.isload = true
						console.log(err, 23432);
						_this.openAuthSettings();
					}
				});
			},
			openAuthSettings() {
				let that = this;
				uni.showModal({
					title: '提示',
					content: '此功能需要获取您的位置信息，请确认授权',
					success: function(modalRes) {
						if (modalRes.confirm) {
							uni.openAppAuthorizeSetting({
								success: function(settingRes) {
									that.getlocationflag = false
									console.log('设置页面打开成功', settingRes);
								},
								fail: function(settingErr) {
									console.log('设置页面打开失败', settingErr);
								}
							});
						}
					}
				});
			},
			getcityInfo() {
				let _this = this
				httpRequest.request('/api/index/getCurrCity', 'POST', {
					lat: this.latitude,
					lng: this.longitude
				}, false, false, true).then(res => {
					console.log(res);
					_this.citytext = res.data.name
				})
			},
			submit() {
				if (this.des == "") {
					httpRequest.toast("请输入视频描述")
					return false
				}
				if(!this.getlocationflag){
					this.openAuthSettings()
					return false
				}
				uni.showLoading({
					mask: true,
					title: "请稍后"
				})
				let data = {
					longitude: this.longitude,
					latitude: this.latitude,
					video_url: this.path,
					video_yy_id: this.video_yy_id,
					des: this.des,
				}
				console.log(uni.getStorageSync("token"));
				console.log(data);
				httpRequest.request('/api/videocl/addVideo', 'GET', data).then(res => {
					uni.hideLoading()
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						setTimeout(() => {
							let url = uni.getStorageSync("lastpage")
							uni.switchTab({
								url
							});
						}, 1000)
					}
				})
			},
		}
	}
</script>

<style>

</style>